<template>
	<!-- 选择地址 -->
	<view>
		<u-navbar title="切换城市" :autoBack="true" :placeholder="true"></u-navbar>
		<view class="cityItem" v-for="item in qhareaList" :key="item.id" :class="{active:item.id===itemData.id}"
			@click="itemClick(item.id,item.name)">
			{{item.name}}
			<image v-if="item.id === itemData.id" src="http://qiniu.suboshimuying.cn/static/city/yse.png" mode=""></image>
		</view>
		<view class="fixedBox">
			<view class="btn" @click="btnClick">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				itemData: {
					id: null,
					name: ""
				},
				qhareaList: [], //地址列表
			};
		},
		onLoad(option) {
			if (option.id) {
				this.itemData.id = Number(option.id)
				console.log(option.id);
			}
			this.getqharea()
		},
		methods: {
			// 地址点击
			itemClick(id, name) {
				this.itemData.id = id
				this.itemData.name = name
			},
			// 确定按钮
			btnClick() {
				const eventChannel = this.getOpenerEventChannel();
				eventChannel.emit('areaBack', this.itemData);
				uni.navigateBack({});
			},
			async getqharea() {
				let res = await this.$api.getqharea()
				this.qhareaList = res.data
			}
		}
	}
</script>

<style>
	page {
		box-sizing: border-box;
		padding-bottom: 188rpx;
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.cityItem {
		box-sizing: border-box;
		padding: 0 32rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 88rpx;
		line-height: 88rpx;
		color: rgba(0, 0, 0, 0.8);
		font-size: 28rpx;
		font-weight: 400;
		letter-spacing: 0.6rpx;
	}

	image {
		margin-right: 40rpx;
		width: 36rpx;
		height: 36rpx;
		opacity: 1;
	}

	.active {
		color: $textColor;
	}

	.fixedBox {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 170rpx;
		box-sizing: border-box;
		padding: 0 32rpx 80rpx;

		.btn {
			width: 100%;
			height: 90rpx;
			background: linear-gradient(131.2deg, rgba(179, 142, 255, 1) 0%, rgba(130, 111, 255, 1) 100%);
			border-radius: 45rpx;
			text-align: center;
			line-height: 90rpx;
			color: #fff;
		}
	}
</style>
